package org.xxpay.manage.ifstore.ctrl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.xxpay.core.common.constant.Constant;
import org.xxpay.core.common.constant.RetEnum;
import org.xxpay.core.common.domain.XxPayResponse;
import org.xxpay.core.common.exception.ServiceException;
import org.xxpay.core.common.util.MyLog;
import org.xxpay.manage.common.config.MainConfig;
import org.xxpay.manage.common.ctrl.BaseController;
import org.xxpay.manage.common.service.CommonService;
import org.xxpay.manage.common.service.RpcCommonService;

import javax.servlet.http.HttpServletRequest;

/** 接口商店 */
@RestController
@RequestMapping(Constant.MGR_CONTROLLER_ROOT_PATH + "/ifstoreApp")
public class IfstoreAppController extends BaseController {

    @Autowired private RpcCommonService rpcCommonService;

    private static final MyLog _log = MyLog.getLog(IfstoreAppController.class);


    /** 请求安装 */
    @RequestMapping("/install")
    public ResponseEntity<?> install(HttpServletRequest request, @RequestParam("file") MultipartFile attachmentFile) {

        try {

            byte[] bytes = attachmentFile.getBytes();

            //调用pay项目， 进行安装
            rpcCommonService.rpcXxPayIfstoreService.overrideInstall(bytes);

        } catch (Exception e) {
            _log.error("安装动态通道失败！", e);
            throw new ServiceException(RetEnum.RET_COMM_OPERATION_FAIL);
        }

        return ResponseEntity.ok(XxPayResponse.buildSuccess());
    }


}
